﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {
  public static partial class IListExtensions {
#region find_first_of
    public static int find_first_of<T>(this IList<T> list, int first, int last, IEnumerable<T> col, Func<T,T,bool> pred) {
      for ( ; first != last; ++first ) {
        foreach ( T val in col ) 
          if ( pred(list[first], val) ) return first;
      }
      return first;
    }

    public static int find_first_of<T>(this IList<T> list, IEnumerable<T> col, Func<T,T,bool> pred) {
      return find_first_of(list,0,list.Count,col,pred);
    }

    public static int find_first_of<T>(this IList<T> list, int first, int last, IEnumerable<T> col) where T : IComparable<T> {
      return find_first_of(list, first, last, col, rel_op.equal_to<T>);
    }

    public static int find_first_of<T>(this IList<T> list, IEnumerable<T> col) where T : IComparable<T> {
      return find_first_of(list, 0, list.Count, col, rel_op.equal_to<T>);
    }

#endregion
  }
}
